package com.xinqi.modules.prepare.paper.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.paper.dto.req.PrepareExamPaperCreateDTO;
import com.xinqi.modules.prepare.paper.dto.req.PrepareExamPaperQueryDTO;
import com.xinqi.modules.prepare.paper.dto.req.PrepareExamPaperUpdateDTO;
import com.xinqi.modules.prepare.paper.dto.rsp.PrepareExamPaperResultDTO;
import com.xinqi.modules.prepare.paper.service.PrepareExamPaperService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 备课区测评卷APP控制层
 *
 * @author: system
 * @date: 2023/03/19
 */
@Tag(name = "prepare-exam-paper-App", description = "备课区测评卷App接口")
//@RestController
@RequestMapping("/app/prepare-exam-paper")
@RequiredArgsConstructor
public class PrepareExamPaperAppController {
    private final PrepareExamPaperService prepareExamPaperService;

    /**
     * 备课区测评卷-分页
     */
    @Operation(summary = "备课区测评卷-分页")
    @GetMapping("/page")
    public R<PageInfo<PrepareExamPaperResultDTO>> page(@ParameterObject PrepareExamPaperQueryDTO dto) {
        PageInfo<PrepareExamPaperResultDTO> page = prepareExamPaperService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 备课区测评卷-详情
     */
    @Operation(summary = "备课区测评卷-详情")
    @GetMapping("/{id}")
    public R<PrepareExamPaperResultDTO> findById(@PathVariable("id") Long id) {
        PrepareExamPaperResultDTO dto = prepareExamPaperService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增备课区测评卷
     */
    @Operation(summary = "新增备课区测评卷")
    @PostMapping
    public R<Long> insert(@RequestBody PrepareExamPaperCreateDTO dto) {
        return R.data(prepareExamPaperService.insert(dto));
    }

    /**
     * 修改备课区测评卷
     */
    @Operation(summary = "修改备课区测评卷")
    @PutMapping("/{id}")
    public R<Boolean> update(@PathVariable("id") Long id, @RequestBody PrepareExamPaperUpdateDTO dto) {
        dto.setId(id);
        return R.data(prepareExamPaperService.updateById(dto));
    }

    /**
     * 删除备课区测评卷
     */
    @Operation(summary = "删除备课区测评卷")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.data(prepareExamPaperService.deleteById(id));
    }

}
